// shipment-record.ts

// 定义数据结构接口
interface IParticipant {
  avatar: string;
}

interface IShipmentDetail {
  name: string;
  unitPrice: number;
  value: number;
  total: number;
}

interface IRecord {
  orderId: string;
  participants: IParticipant[];
  paymentMethod: '微信' | '支付宝' | '现金';
  shipper: string;
  details: IShipmentDetail[];
  totalAmount: string;
  shipmentTime: string;
  remark?: string;
  images?: string[];
}

Page({
  data: {
    isLoading: true,
    recordList: [] as IRecord[],
  },

  onLoad() {
    this.fetchData();
  },

  /**
   * 模拟获取数据
   */
  fetchData() {
    this.setData({ isLoading: true });
    // 模拟网络请求
    setTimeout(() => {
      const mockData: IRecord[] = [
        {
          orderId: '...6789',
          participants: [
            { avatar: 'https://mp-7734cf55-8926-4ed0-a608-1302ac9a2a87.cdn.bspapp.com/avatar.png' },
            { avatar: 'https://mp-7734cf55-8926-4ed0-a608-1302ac9a2a87.cdn.bspapp.com/avatar.png' },
            { avatar: 'https://mp-7734cf55-8926-4ed0-a608-1302ac9a2a87.cdn.bspapp.com/avatar.png' },
          ],
          paymentMethod: '微信',
          shipper: '张三',
          details: [
            { name: 'T恤', unitPrice: 0.6, value: 20, total: 12.0 },
            { name: '牛仔裤', unitPrice: 1.2, value: 15, total: 18.0 },
            { name: '外套', unitPrice: 2.5, value: 5, total: 12.5 },
          ],
          totalAmount: '42.50',
          shipmentTime: '2023-10-27 14:30',
          remark: '客户要求尽快发货，已打包完毕，等待揽收。',
          images: [
            'https://img.yzcdn.cn/vant/leaf.jpg',
            'https://img.yzcdn.cn/vant/tree.jpg',
          ],
        },
        {
          orderId: '...1234',
          participants: [
            { avatar: 'https://mp-7734cf55-8926-4ed0-a608-1302ac9a2a87.cdn.bspapp.com/avatar.png' },
            { avatar: 'https://mp-7734cf55-8926-4ed0-a608-1302ac9a2a87.cdn.bspapp.com/avatar.png' },
          ],
          paymentMethod: '支付宝',
          shipper: '李四',
          details: [
            { name: '儿童玩具', unitPrice: 5.0, value: 10, total: 50.0 },
            { name: '文具盒', unitPrice: 3.2, value: 30, total: 96.0 },
          ],
          totalAmount: '146.00',
          shipmentTime: '2023-10-26 10:15',
          remark: '易碎品，已加固包装。',
        },
      ];
      this.setData({
        recordList: mockData,
        isLoading: false,
      });
    }, 1500); // 模拟1.5秒加载时间
  },

  /**
   * 预览图片
   */
  handlePreviewImage(e: WechatMiniprogram.TouchEvent) {
    const { current, urls } = e.currentTarget.dataset;
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: urls, // 需要预览的图片http链接列表
    });
  },
});
